<?php
namespace Home\Controller;
use Think\Controller;
class ProfessorController extends Controller {
    public function index() {
        $news = D('News');
        $list = $news->where('type=3')->field('id,title,summary')->order('date desc')->limit(1)->select();
        $data = $list[0];
        $this->assign('data', $data);

        $resource = D('Resource');
        $list = $news->where('type=4')->field('id,title,summary,pid')->order('date desc')->limit(4)->select();
        foreach ($list as &$v) {
            $r = $resource->where('id=%d', $v['pid'])->find();
            $v['path'] = $r['path'];
        }
        $this->assign('list', $list);

        $this->display('./Public/professor.html');
    }

    public function plist() {
        $news = D('News');
        $list = $news->where('type=5')->field('id,title,summary,pid')->order('date desc')->limit(6)->select();
        $resource = D('Resource');
        foreach ($list as &$v) {
            $r = $resource->where('id=%d', $v['pid'])->find();
            $v['path'] = $r['path'];
        }
        $this->assign('list1', array_slice($list, 0, 3));
        count($list)>3 && $this->assign('list2', array_slice($list, 3, 3));

        $this->display('./Public/pro_list.html');
    }

    public function view($id) {
        $news = D('News');
        $result = $news->where("id=$id")->find();
        $this->assign('content', htmlspecialchars_decode(stripslashes($result['content'])));
        $this->display('./Public/subview.html');
    }
}